package app.android.alampang.utility;

import android.app.Activity;
import android.content.Intent;
import android.content.Context;
import android.os.Bundle;

/**
 * Created by Supanut on 1/11/2015.
 */
public class NavigationService
{
    private static NavigationService _instance;

    private NavigationService(){}

    private Context context;

    public static NavigationService getInstance()
    {
        if (_instance == null)
            _instance = new NavigationService();

        return _instance;
    }

    public void navigate(Context context, Class<?> toClass, boolean finish)
    {
        this.context = context;
        this.context.startActivity(new Intent(context, toClass));

        if (finish)
           ((Activity)context).finish();
    }

    public void navigate(Context context, Class<?> toClass, Bundle param, boolean finish)
    {
        this.context = context;
        Intent intent = new Intent();
        if (param != null)
            intent.putExtras(param);

        intent.setClass(this.context, toClass);

        this.context.startActivity(intent);

        if (finish)
           ((Activity)context).finish();
    }

    public void back()
    {
        if (this.context != null)
            ((Activity)this.context).finish();
    }
}
